package com.jbp.job;

import com.jbp.redis.RedisConfigService;
import com.jbp.service.SendGiftRecordService;
import com.jbp.service.TencentIdentifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**排行榜任务*/
@Component
@Configuration
public class RankJob {

    @Autowired
    private SendGiftRecordService sendGiftRecordService;
    @Autowired
    private TencentIdentifyService tencentIdentifyService;

    @Autowired
    private RedisConfigService redisConfigService;

    /**
     * 刷新排行榜数据
     */
    @Scheduled(fixedDelay = 1000)
    public void refreshData(){
        if (redisConfigService.setLock("main_rank", 10)) {
            sendGiftRecordService.cacheHeartList();
            sendGiftRecordService.cacheSenderList();
        }
    }

    @Scheduled(fixedDelay = 1000*60)
    public void refreshTencentIdentifyToken(){
        if (redisConfigService.setLock("refreshTencentIdentifyToken", 60*20)) {
            tencentIdentifyService.cacheAccessToken();
            tencentIdentifyService.cacheTicket();
        }
    }


}
